import Cookies from 'js-cookie'
import Vue from 'vue'
let vn = new Vue()
let gmapUtil = {
    // 自定义叠加层的样式
    // CoordMapType: function (tileSize) {
    //     this.tileSize = tileSize
    //     this.getTile = function (coord, zoom, ownerDocument) {
    //         let div = ownerDocument.createElement('DIV')
    //         let ymax = 1 << zoom
    //         let y = ymax - coord.y - 1
    //         div.innerHTML = coord.x + ',' + y + ',' + zoom
    //         div.style.width = this.tileSize.width + 'px'
    //         div.style.height = this.tileSize.height + 'px'
    //         div.style.fontSize = '10'
    //         div.style.borderStyle = 'solid'
    //         div.style.borderWidth = '1px'
    //         div.style.borderColor = '#AAAAAA'
    //         return div
    //     }
    // },
    LocalMapType: {
        tileSize: new google.maps.Size(256, 256),
        maxZoom: 8,
        minZoom: 0,
        name: '本地',
        getTile: function (coord, zoom, ownerDocument) {
            var img = ownerDocument.createElement('img')
            let strURL
            img.style.width = this.tileSize.width + 'px'
            img.style.height = this.tileSize.height + 'px'
            if (process.env.NODE_ENV === 'production') {
                strURL = vn.GOOGLE_MAP + zoom + '/' + coord.x + '/' + coord.y + '.png'
            } else {
                strURL = 'http://192.168.31.219:10000/turkey_map/' + zoom + '/' + coord.x + '/' + coord.y + '.png'
            }
            img.src = strURL
            return img
        }
    },
    myOptions: {
        // 经纬度
        center: new google.maps.LatLng(39.8, 32.7),
        // 层级
        zoom: 8,
        // 关闭街景全景图
        streetViewControl: false,
        // 关闭切换地图类型
        mapTypeControl: false,
        // 关闭全屏按钮
        fullscreenControl: false
        // mapTypeControlOptions: {
        //     mapTypeIds: ['local', google.maps.MapTypeId.ROADMAP]
        // }
    },
    initMap: function (DOM) {
        return new google.maps.Map(
            document.getElementById(DOM),
            this.myOptions
        )
    },
    markerOptions: function (map) {
        return {
            map: map,
            drawingMode: 'marker',
            drawingControl: false,
            markerOptions: { icon: process.env.NODE_ENV === 'production' ? '../../dist/static/img/spotlight-poi2.png' : '../../static/img/spotlight-poi2.png' }
        }
    },
    polygonOptions: function (map) {
        return {
            map: map,
            drawingMode: 'polygon',
            drawingControl: false
        }
    },
    circleOptions: function (map) {
        return {
            map: map,
            drawingMode: 'circle',
            drawingControl: false
        }
    },
    polylineOptions: function (map) {
        return {
            map: map,
            drawingMode: 'polyline',
            drawingControl: false
        }
    },
    rectangleOptions: function (map) {
        return {
            map: map,
            drawingMode: 'rectangle',
            drawingControl: false
        }
    },
    nullOptions: function (map) {
        return {
            map: map,
            drawingMode: null,
            drawingControl: false
        }
    },
    removeMarkersInMap: function () {
        Cookies.remove('MapReloadData')
    },
    setMapOnAll: function (map, markers) {
        for (var i = 0; i < markers.length; i++) {
            markers[i].setMap(map)
        }
    }

}

export default gmapUtil